package tech.wenxu.ssoprovider.pojo;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author zhaowenxu
 * @date 2020/4/13 14:55
 */
@Data
public class BasePojo implements Serializable {

    private static final long serialVersionUID = 2481036613706719302L;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime created;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updated;

    @Override
    public String toString() {
        return JSON.toJSONString(this, true);
    }

    /**
     * 添加方法调用
     */
    public void addObject() {
        LocalDateTime nowDate = LocalDateTime.now();
        this.created = nowDate;
        this.updated = nowDate;
    }

    /**
     * 修改方法调用
     */
    public void updObject() {
        this.updated = LocalDateTime.now();
    }
}
